#pragma once
#ifndef _RAYTRACER_NUMERIC_H
#define _RAYTRACER_NUMERIC_H

#include <math.h>
#include <maya/MFloatPoint.h>

//---------------------------------------------------------------------------
inline bool NearlyEq(float a, float b, float eps=0.00001){
  return abs(a-b) < eps;
}

//---------------------------------------------------------------------------
inline bool NearlyEq(double a, double b, double eps=0.000000001){
  return abs(a-b) < eps;
}

//---------------------------------------------------------------------------
inline int RoundToInt(double val) {
  return (int)floor(val + 0.5);
}

//---------------------------------------------------------------------------
inline int RoundToInt(float val) {
  return (int)floor(val + 0.5f);
}

//---------------------------------------------------------------------------
inline int sgn(float val) {
    return (0 < val) - (val < 0);
}

//---------------------------------------------------------------------------
inline float clamptop(float val, float clampval) {
  return (val < clampval) ? val : clampval;
}

//---------------------------------------------------------------------------
inline double clamptop(double val, double clampval) {
  return (val < clampval) ? val : clampval;
}

//---------------------------------------------------------------------------
inline float clampbot(float val, float clampval) {
  return (val > clampval) ? val : clampval;
}

//---------------------------------------------------------------------------
inline double clampbot(double val, double clampval) {
  return (val > clampval) ? val : clampval;
}

//---------------------------------------------------------------------------
inline float dist(const MFloatPoint& p1, const MFloatPoint& p2) {
  return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) + (p1.z-p2.z)*(p1.z-p2.z));
}

//---------------------------------------------------------------------------
inline float toDegrees(float radians){
  return radians*(180.0f/float(M_PI));
}

//---------------------------------------------------------------------------
inline double toDegrees(double radians){
  return radians*(180.0/M_PI);
}

//---------------------------------------------------------------------------
inline float toRadians(float degrees){
  return degrees*(float(M_PI)/180.0f);
}

//---------------------------------------------------------------------------
inline double toRadians(double degrees){
  return degrees*(M_PI/180.0);
}

#endif